<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <h1 data-lake-id="bVODd" id="bVODd"><span data-lake-id="ue29d4aa5" id="ue29d4aa5">典型回答</span></h1>
  <p data-lake-id="u89d1835e" id="u89d1835e"><br></p>
  <p data-lake-id="u4298dfc7" id="u4298dfc7"><span data-lake-id="u00011cb4" id="u00011cb4">先看过上面这篇，我们就能知道，Spring的可以分为6个小的阶段：实例化、设置属性值、初始化、注册Destruction回调、Bean的正常使用以及Bean的销毁。</span></p>
  <p data-lake-id="uf54e0298" id="uf54e0298"><span data-lake-id="uce25b429" id="uce25b429">​</span><br></p>
  <p data-lake-id="ufd7358db" id="ufd7358db"><span data-lake-id="ue5c5c3a4" id="ue5c5c3a4">我们再把初始化的的这个过程单独拿出来展开介绍一下。</span></p>
  <p data-lake-id="u9f4d4f15" id="u9f4d4f15"><span data-lake-id="udd5a37a1" id="udd5a37a1">​</span><br></p>
  <p data-lake-id="u261e0dc6" id="u261e0dc6"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1699966914771-319aeb73-ee91-46f8-b32a-cba0e57bcc74.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_21%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u98da5fe8" id="u98da5fe8"><span data-lake-id="u40b2a432" id="u40b2a432">​</span><br></p>
  <p data-lake-id="ue3b25bb5" id="ue3b25bb5"><span data-lake-id="u67fdb8a0" id="u67fdb8a0">首先先看一下初始化和实例化的区别是什么？</span></p>
  <p data-lake-id="ubbf7cf74" id="ubbf7cf74"><span data-lake-id="ud3f2432b" id="ud3f2432b">​</span><br></p>
  <p data-lake-id="udf35671f" id="udf35671f"><span data-lake-id="udbac53d6" id="udbac53d6">在Spring框架中，初始化和实例化是两个不同的概念：</span></p>
  <p data-lake-id="u9508a897" id="u9508a897"><strong><span data-lake-id="u95cc2d04" id="u95cc2d04">实例化（Instantiation）</span></strong><span data-lake-id="u2185e1bc" id="u2185e1bc">：</span></p>
  <ul list="ue35252bd">
   <li fid="u27d7e054" data-lake-id="uf62d86d7" id="uf62d86d7"><span data-lake-id="u2e08b927" id="u2e08b927">实例化是创建对象的过程。在Spring中，这通常指的是通过调用类的构造器来创建Bean的实例。这是对象生命周期的开始阶段。对应doCreateBean中的createBeanInstance方法。</span></li>
  </ul>
  <p data-lake-id="u38fc7ace" id="u38fc7ace"><strong><span data-lake-id="ub88e25d4" id="ub88e25d4">初始化（Initialization）：</span></strong></p>
  <ul list="u8b320eb9">
   <li fid="u888462a0" data-lake-id="u2e2e7ffd" id="u2e2e7ffd"><span data-lake-id="u1fd4e292" id="u1fd4e292">初始化是在Bean实例创建后，进行一些设置或准备工作的过程。在Spring中，包括设置Bean的属性，调用各种前置&amp;后置处理器。对应doCreateBean中的populateBean和initializeBean方法。</span></li>
  </ul>
  <p data-lake-id="u94fa10d2" id="u94fa10d2"><span data-lake-id="uc9424d6e" id="uc9424d6e">​</span><br></p>
  <p data-lake-id="ue38467ea" id="ue38467ea"><span data-lake-id="u91757c55" id="u91757c55">下面是SpringBean的实例化+初始化的完整过程：<br><br></span></p>
  <h3 data-lake-id="gzG20" id="gzG20"><span data-lake-id="u39c7dbb0" id="u39c7dbb0">实例化Bean</span></h3>
  <p data-lake-id="u77b327b0" id="u77b327b0"><span data-lake-id="u471cf3a4" id="u471cf3a4">Spring容器在这一步创建Bean实例。其主要代码在AbstractAutowireCapableBeanFactory类中的createBeanInstance方法中实现：</span></p>
  <p data-lake-id="u1147d50e" id="u1147d50e"><span data-lake-id="u7130f5a3" id="u7130f5a3">​</span><br></p>
  <pre lang="java"><code>
protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, Object[] args) {
    // 解析Bean的类，确保Bean的类在这个点已经被确定
    Class&lt;?&gt; beanClass = resolveBeanClass(mbd, beanName);

    // 检查Bean的访问权限，确保非public类允许访问
    if (beanClass != null &amp;&amp; !Modifier.isPublic(beanClass.getModifiers()) &amp;&amp; !mbd.isNonPublicAccessAllowed()) {
        throw new BeanCreationException(mbd.getResourceDescription(), beanName,
                "Bean class isn't public, and non-public access not allowed: " + beanClass.getName());
    }

    // 如果Bean定义中指定了工厂方法，则通过工厂方法创建Bean实例
    if (mbd.getFactoryMethodName() != null) {
        return instantiateUsingFactoryMethod(beanName, mbd, args);
    }

    // 当重新创建相同的Bean时的快捷路径
    boolean resolved = false;
    boolean autowireNecessary = false;
    if (args == null) {
        synchronized (mbd.constructorArgumentLock) {
            // 如果构造方法或工厂方法已经被解析，直接使用解析结果
            if (mbd.resolvedConstructorOrFactoryMethod != null) {
                resolved = true;
                autowireNecessary = mbd.constructorArgumentsResolved;
            }
        }
    }
    if (resolved) {
        // 如果需要自动装配构造函数参数，则调用相应方法进行处理
        if (autowireNecessary) {
            return autowireConstructor(beanName, mbd, null, null);
        }
        else {
            // 否则使用无参构造函数或默认构造方法创建实例
            return instantiateBean(beanName, mbd);
        }
    }

    // 通过BeanPostProcessors确定构造函数候选
    Constructor&lt;?&gt;[] ctors = determineConstructorsFromBeanPostProcessors(beanClass, beanName);
    // 如果有合适的构造函数或需要通过构造函数自动装配，则使用相应的构造函数创建实例
    if (ctors != null || mbd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR ||
            mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) {
        return autowireConstructor(beanName, mbd, ctors, args);
    }

    // 没有特殊处理，使用默认的无参构造函数创建Bean实例
    return instantiateBean(beanName, mbd);
}

</code></pre>
  <p data-lake-id="u1984ea8e" id="u1984ea8e"><span data-lake-id="u6b04a7a1" id="u6b04a7a1">​</span><br></p>
  <p data-lake-id="u45488697" id="u45488697"><span data-lake-id="u12e2a3ca" id="u12e2a3ca">其实就是先确保这个Bean对应的类已经被加载，然后确保它是public的，然后如果有工厂方法，则直接调用工厂方法创建一本Bean，如果没有的话就调用它的构造方法来创建这个Bean。</span></p>
  <p data-lake-id="u5141d9f6" id="u5141d9f6"><span data-lake-id="u842bbbd2" id="u842bbbd2">​</span><br></p>
  <p data-lake-id="ufeaa4851" id="ufeaa4851"><span data-lake-id="u003f3e3a" id="u003f3e3a">这里需要注意的是，在Spring的完整Bean创建和初始化流程中，容器会在调用createBeanInstance之前检查Bean定义的作用域。如果是Singleton，容器会在其内部单例缓存中查找现有实例。如果实例已存在，它将被重用；如果不存在，才会调用createBeanInstance来创建新的实例。</span></p>
  <p data-lake-id="ua8af91a1" id="ua8af91a1"><span data-lake-id="u2f7e8cff" id="u2f7e8cff">​</span><br></p>
  <pre lang="java"><code>
BeanWrapper instanceWrapper = null;
if (mbd.isSingleton()) {
    instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);
}
if (instanceWrapper == null) {
    instanceWrapper = createBeanInstance(beanName, mbd, args);
}
</code></pre>
  <p data-lake-id="ue506cb74" id="ue506cb74"><span data-lake-id="uc69a52a8" id="uc69a52a8">​</span><br></p>
  <p data-lake-id="ue0a6daea" id="ue0a6daea"><span data-lake-id="u63dcfdc4" id="u63dcfdc4">​</span><br></p>
  <p data-lake-id="u1ea4e96a" id="u1ea4e96a"><span data-lake-id="u438317b3" id="u438317b3">下一步就应该要到设置属性值了，但是在这之前还有一个重要的东西要讲，那就是三级解决循环依赖，在doCreateBean方法中：</span></p>
  <p data-lake-id="u50e2d083" id="u50e2d083"><span data-lake-id="u123d1751" id="u123d1751">​</span><br></p>
  <pre lang="java"><code>
protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args)
			throws BeanCreationException {

		// 实例化bean
		// ...

        // Eagerly cache singletons to be able to resolve circular references
		// even when triggered by lifecycle interfaces like BeanFactoryAware.
		boolean earlySingletonExposure = (mbd.isSingleton() &amp;&amp; this.allowCircularReferences &amp;&amp;
				isSingletonCurrentlyInCreation(beanName));
		if (earlySingletonExposure) {
			if (logger.isDebugEnabled()) {
				logger.debug("Eagerly caching bean '" + beanName +
						"' to allow for resolving potential circular references");
			}
			addSingletonFactory(beanName, new ObjectFactory&lt;Object&gt;() {
				@Override
				public Object getObject() throws BeansException {
					return getEarlyBeanReference(beanName, mbd, bean);
				}
			});
		}

        // ...

		
        //设置属性值
		//初始化Bean

    	// ...

		// 注册Bean的销毁回调

		return exposedObject;
	}
</code></pre>
  <p data-lake-id="ub141b059" id="ub141b059"><br></p>
  <p data-lake-id="u88b97b37" id="u88b97b37"><span data-lake-id="ub5505287" id="ub5505287">这部分就是关于三级缓存解决循环依赖的内容。</span></p>
  <p data-lake-id="udde461a7" id="udde461a7"><span data-lake-id="uc40f1748" id="uc40f1748">​</span><br></p>
  <p data-lake-id="uc0d0cf36" id="uc0d0cf36"><br></p>
  <h3 data-lake-id="gB6St" id="gB6St"><strong><span data-lake-id="u40abe061" id="u40abe061">设置属性值</span></strong></h3>
  <p data-lake-id="ua707e474" id="ua707e474"><br></p>
  <p data-lake-id="u3e93b9ed" id="u3e93b9ed"><span data-lake-id="u92def929" id="u92def929">populateBean方法是Spring Bean生命周期中的一个关键部分，负责将属性值应用到新创建的Bean实例。它处理了自动装配、属性注入、依赖检查等多个方面。代码如下：</span></p>
  <p data-lake-id="u25310fa1" id="u25310fa1"><span data-lake-id="u82a79ce9" id="u82a79ce9">​</span><br></p>
  <pre lang="java"><code>
protected void populateBean(String beanName, RootBeanDefinition mbd, BeanWrapper bw) {
    // 获取Bean定义中的属性值
    PropertyValues pvs = mbd.getPropertyValues();

    // 如果BeanWrapper为空，则无法设置属性值
    if (bw == null) {
        if (!pvs.isEmpty()) {
            throw new BeanCreationException(
                    mbd.getResourceDescription(), beanName, "Cannot apply property values to null instance");
        }
        else {
            // 对于null实例，跳过设置属性阶段
            return;
        }
    }

    // 在设置属性之前，给InstantiationAwareBeanPostProcessors机会修改Bean状态
    // 这可以用于支持字段注入等样式
    boolean continueWithPropertyPopulation = true;

    // 如果Bean不是合成的，并且存在InstantiationAwareBeanPostProcessor，执行后续处理
    if (!mbd.isSynthetic() &amp;&amp; hasInstantiationAwareBeanPostProcessors()) {
        for (BeanPostProcessor bp : getBeanPostProcessors()) {
            if (bp instanceof InstantiationAwareBeanPostProcessor) {
                InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
                if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {
                    continueWithPropertyPopulation = false;
                    break;
                }
            }
        }
    }

    // 如果上述处理后决定不继续，则返回
    if (!continueWithPropertyPopulation) {
        return;
    }

    // 根据自动装配模式（按名称或类型），设置相关的属性值
    if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME ||
            mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
        MutablePropertyValues newPvs = new MutablePropertyValues(pvs);

        // 如果是按名称自动装配，添加相应的属性值
        if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME) {
            autowireByName(beanName, mbd, bw, newPvs);
        }

        // 如果是按类型自动装配，添加相应的属性值
        if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
            autowireByType(beanName, mbd, bw, newPvs);
        }

        pvs = newPvs;
    }

    // 检查是否需要进行依赖性检查
    boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors();
    boolean needsDepCheck = (mbd.getDependencyCheck() != RootBeanDefinition.DEPENDENCY_CHECK_NONE);

    // 如果需要，则进行依赖性检查
    if (hasInstAwareBpps || needsDepCheck) {
        PropertyDescriptor[] filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);
        if (hasInstAwareBpps) {
            for (BeanPostProcessor bp : getBeanPostProcessors()) {
                if (bp instanceof InstantiationAwareBeanPostProcessor) {
                    InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
                    pvs = ibp.postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName);
                    if (pvs == null) {
                        return;
                    }
                }
            }
        }
        if (needsDepCheck) {
            checkDependencies(beanName, mbd, filteredPds, pvs);
        }
    }

    // 应用属性值
    applyPropertyValues(beanName, mbd, bw, pvs);
}

</code></pre>
  <p data-lake-id="ud06691ef" id="ud06691ef"><br></p>
  <p data-lake-id="ubb5a3df2" id="ubb5a3df2"><span data-lake-id="u8f13fd5e" id="u8f13fd5e">逻辑也比较清晰，就是把各种属性进行初始化。</span></p>
  <p data-lake-id="uc4df485b" id="uc4df485b"><span data-lake-id="u4a5f20b4" id="u4a5f20b4">​</span><br></p>
  <h3 data-lake-id="aTSVh" id="aTSVh"><span data-lake-id="ub3c38875" id="ub3c38875">initializeBean方法</span></h3>
  <p data-lake-id="u5d807fb7" id="u5d807fb7"><br></p>
  <p data-lake-id="u2e473f93" id="u2e473f93"><span data-lake-id="ucff7933f" id="ucff7933f">这个方法是初始化中的关键方法，后面要介绍的几个步骤就在这个方法中编排的：</span></p>
  <pre lang="java"><code>
protected Object initializeBean(final String beanName, final Object bean, RootBeanDefinition mbd) {

    //...
    //检查Aware
    invokeAwareMethods(beanName, bean);
    
	//调用BeanPostProcessor的前置处理方法
    Object wrappedBean = bean;
    if (mbd == null || !mbd.isSynthetic()) {
        wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
    }

    //调用InitializingBean的afterPropertiesSet方法或自定义的初始化方法及自定义init-method方法
    try {
        invokeInitMethods(beanName, wrappedBean, mbd);
    }
    catch (Throwable ex) {
        throw new BeanCreationException(
                (mbd != null ? mbd.getResourceDescription() : null),
                beanName, "Invocation of init method failed", ex);
    }
    //调用BeanPostProcessor的后置处理方法
    if (mbd == null || !mbd.isSynthetic()) {
        wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
    }
    return wrappedBean;
}
</code></pre>
  <p data-lake-id="u012196d7" id="u012196d7"><span data-lake-id="u58c8eb05" id="u58c8eb05">​</span><br></p>
  <h3 data-lake-id="ZhDDB" id="ZhDDB"><strong><span data-lake-id="u13c64ded" id="u13c64ded">检查Aware</span></strong></h3>
  <p data-lake-id="ue7ee2290" id="ue7ee2290"><br></p>
  <pre lang="java"><code>
private void invokeAwareMethods(final String beanName, final Object bean) {
    if (bean instanceof Aware) {
        if (bean instanceof BeanNameAware) {
            ((BeanNameAware) bean).setBeanName(beanName);
        }
        if (bean instanceof BeanClassLoaderAware) {
            ((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
        }
        if (bean instanceof BeanFactoryAware) {
            ((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
        }
    }
}
</code></pre>
  <p data-lake-id="ub009b73e" id="ub009b73e"><br></p>
  <p data-lake-id="u2f5c9555" id="u2f5c9555"><span data-lake-id="uf11aa3f0" id="uf11aa3f0">就是检查这个Bean是不是实现了BeanNameAware、BeanClassLoaderAware等这些Aware接口，Spring容器会调用它们的方法进行处理。</span></p>
  <p data-lake-id="ub15c2a09" id="ub15c2a09"><span data-lake-id="u0b29e90c" id="u0b29e90c">​</span><br></p>
  <p data-lake-id="ubd1e731f" id="ubd1e731f"><span data-lake-id="u725a40f7" id="u725a40f7">这些Aware接口提供了一种机制，使得Bean可以与Spring框架的内部组件交互，从而更灵活地利用Spring框架提供的功能。</span></p>
  <p data-lake-id="u43debf9d" id="u43debf9d"><span data-lake-id="u70c9073c" id="u70c9073c">​</span><br></p>
  <ul list="u3be03c57">
   <li fid="u2b1f5065" data-lake-id="ueb1c8826" id="ueb1c8826"><span data-lake-id="u8cb3029c" id="u8cb3029c">BeanNameAware: 通过这个接口，Bean可以获取到自己在Spring容器中的名字。这对于需要根据Bean的名称进行某些操作的场景很有用。</span></li>
   <li fid="u2b1f5065" data-lake-id="u431e3585" id="u431e3585"><span data-lake-id="u058c262e" id="u058c262e">BeanClassLoaderAware: 这个接口使Bean能够访问加载它的类加载器。这在需要进行类加载操作时特别有用，例如动态加载类。</span></li>
   <li fid="u2b1f5065" data-lake-id="u93e2eb21" id="u93e2eb21"><span data-lake-id="uf7299e65" id="uf7299e65">BeanFactoryAware：通过这个接口可以获取对 BeanFactory 的引用，获得对 BeanFactory 的访问权限</span></li>
  </ul>
  <p data-lake-id="u90f09026" id="u90f09026"><span data-lake-id="u887720d3" id="u887720d3"><br><br></span></p>
  <h3 data-lake-id="GWOVh" id="GWOVh"><span data-lake-id="u1c9b77ce" id="u1c9b77ce">调用BeanPostProcessor的前置处理方法</span></h3>
  <p data-lake-id="u09889a89" id="u09889a89"><br></p>
  <p data-lake-id="ub33c4a55" id="ub33c4a55"><span data-lake-id="uaf01b8ad" id="uaf01b8ad">BeanPostProcessor是Spring IOC容器给我们提供的一个扩展接口，他的主要作用主要是帮我们在Bean的初始化前后添加一些自己的逻辑处理，Spring内置了很多BeanPostProcessor，我们也可以定义一个或者多个 BeanPostProcessor 接口的实现，然后注册到容器中。</span></p>
  <p data-lake-id="uea58a69a" id="uea58a69a"><span data-lake-id="uf5edb3ec" id="uf5edb3ec">​</span><br></p>
  <p data-lake-id="uf9fea3d6" id="uf9fea3d6"><span data-lake-id="u7bbf879f" id="u7bbf879f">调用BeanPostProcessor的前置处理方法是在applyBeanPostProcessorsBeforeInitialization这个方法中实现的，代码如下：</span></p>
  <p data-lake-id="u3da33797" id="u3da33797"><span data-lake-id="u300dbcb6" id="u300dbcb6">​</span><br></p>
  <pre lang="java"><code>
@Override
public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
        throws BeansException {

    Object result = existingBean;
    for (BeanPostProcessor processor : getBeanPostProcessors()) {
        result = processor.postProcessBeforeInitialization(result, beanName);
        if (result == null) {
            return result;
        }
    }
    return result;
}
</code></pre>
  <p data-lake-id="ub5b20e97" id="ub5b20e97"><br></p>
  <p data-lake-id="ub2fccc58" id="ub2fccc58"><br></p>
  <p data-lake-id="u7a298fb7" id="u7a298fb7"><span data-lake-id="u6ef70190" id="u6ef70190">其实就是遍历所有的BeanPostProcessor的实现，执行他的postProcessBeforeInitialization方法。</span></p>
  <p data-lake-id="u51420935" id="u51420935"><br></p>
  <h3 data-lake-id="oOA89" id="oOA89"><strong><span data-lake-id="u8b1d434e" id="u8b1d434e">调用InitializingBean的afterPropertiesSet方法或自定义的初始化方法</span></strong></h3>
  <p data-lake-id="ua6c9a021" id="ua6c9a021"><br></p>
  <p data-lake-id="ud40a75fe" id="ud40a75fe"><span data-lake-id="u0a5feb70" id="u0a5feb70">占坑，暂时先不展开。</span></p>
  <p data-lake-id="uf532b15b" id="uf532b15b"><br></p>
  <h3 data-lake-id="HFqDE" id="HFqDE"><strong><span data-lake-id="u3e153f81" id="u3e153f81">调用BeanPostProcessor的后置处理方法</span></strong></h3>
  <p data-lake-id="u554d64b2" id="u554d64b2"><br></p>
  <p data-lake-id="ue0e17fd9" id="ue0e17fd9"><span data-lake-id="u91675a7e" id="u91675a7e">调用BeanPostProcessor的后置处理方法是在applyBeanPostProcessorsAfterInitialization这个方法中实现的，代码如下：</span></p>
  <p data-lake-id="u42782cc5" id="u42782cc5"><br></p>
  <pre lang="java"><code>
@Override
public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
        throws BeansException {

    Object result = existingBean;
    for (BeanPostProcessor processor : getBeanPostProcessors()) {
        result = processor.postProcessAfterInitialization(result, beanName);
        if (result == null) {
            return result;
        }
    }
    return result;
}

</code></pre>
  <p data-lake-id="uf85a4c01" id="uf85a4c01"><br></p>
  <p data-lake-id="u1ef7905f" id="u1ef7905f"><span data-lake-id="u09349d0b" id="u09349d0b">其实就是遍历所有的BeanPostProcessor的实现，执行他的postProcessAfterInitialization方法。</span></p>
  <p data-lake-id="u9702aafc" id="u9702aafc"><br></p>
  <p data-lake-id="u27844eaa" id="u27844eaa"><span data-lake-id="u67b18a79" id="u67b18a79">这里面需要我们关注的就是</span><strong><span data-lake-id="ucc09f790" id="ucc09f790">AnnotationAwareAspectJAutoProxyCreator（继承自AspectJAwareAdvisorAutoProxyCreator），</span></strong><span data-lake-id="uc9848814" id="uc9848814">他们也是BeanPostProcessor的实现，他之所以重要，是因为在他的postProcessAfterInitialization 后置处理方法。</span></p>
  <p data-lake-id="u0b682948" id="u0b682948"><span data-lake-id="ucc99a7c5" id="ucc99a7c5"></span></p>
  <pre lang="java"><code>
/**
 * Create a proxy with the configured interceptors if the bean is
 * identified as one to proxy by the subclass.
 * @see #getAdvicesAndAdvisorsForBean
 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (bean != null) {
        Object cacheKey = getCacheKey(bean.getClass(), beanName);
        if (this.earlyProxyReferences.remove(cacheKey) != bean) {
            return wrapIfNecessary(bean, beanName, cacheKey);
        }
    }
    return bean;
}

</code></pre>
  <p data-lake-id="uf67748d2" id="uf67748d2"><span data-lake-id="u3977cac0" id="u3977cac0">​</span><br></p>
  <p data-lake-id="u58628042" id="u58628042"><span data-lake-id="u9c1f83ea" id="u9c1f83ea">在这里完成AOP的代理的创建。</span></p>
  <p data-lake-id="uf4e7c479" id="uf4e7c479"><span data-lake-id="ub4278071" id="ub4278071">​</span><br></p>
  <p data-lake-id="u96ae4a70" id="u96ae4a70"><br></p>
 </body>
</html>